

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRootPane;
import javax.swing.JScrollPane;
import javax.swing.JTree;

public class OfFrame extends JFrame implements ActionListener{
    
	private TailDialog panelDialog;
	private JButton button;
	public OfFrame(){
		super("测试");
		this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME );
		this.setUndecorated(true);
		this.setSize(new Dimension(200, 500));
		this.setLocation(300, 100);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = (JPanel) this.getContentPane();
		
		panel.setLayout(new BorderLayout());
		JScrollPane jspane = new JScrollPane();
		JTree tree = new JTree();
		jspane.setViewportView(tree);
		
		button = new JButton("显示面板");
		button.setContentAreaFilled(false);
		button.setFocusPainted(false);
		button.setBorderPainted(true);
		button.setBackground(Color.white);
		
		button.addActionListener(this);
		
		panel.add(jspane, BorderLayout.CENTER);
		panel.add(button, BorderLayout.SOUTH);
		
		JMenuBar mb = new JMenuBar();
		JMenu m = new JMenu("文件");
		m.add(new JMenuItem("测试"));
		mb.add(m);
	//	this.setJMenuBar(mb);
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		new OfFrame().setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		if(panelDialog != null && panelDialog.isVisible()){
			button.setText("显示面板");
			collapsePanel();
		}else{
			button.setText("关闭面板");
			showPanel();
		}
	}

	private void showPanel() {
	//	System.out.println(this.getLocationOnScreen().y);
	//	System.out.println(this.getRootPane().getLocationOnScreen().y);
	//	System.out.println(this.getLayeredPane().getLocationOnScreen().y);
	//	System.out.println(this.getContentPane().getLocationOnScreen().y);
		panelDialog = new TailDialog(this);
		OuterPanel outerPanel = new OuterPanel();
		panelDialog.setContentPane(outerPanel);
		panelDialog.pack();
		panelDialog.showDialog();
	}
	
	private void collapsePanel(){
		panelDialog.closeDialog();
		panelDialog = null;
	}

}
